<?php

namespace App\Http\Controllers\Api;

use App\Models\Article;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class ArticleController extends ApiController
{
    public function getAllArticle(Request $request){
        $page = isset($request['page']) ? $request['page'] : 1;
        $pageSize = isset($request['pageSize']) ? $request['pageSize'] : 15;
        $res = Article::orderby('created_at','desc')
            ->offset(($page-1)*$pageSize)
            ->limit($pageSize)
            ->get();
        return self::returnAjax(['list'=>$res], 200, "所有文章");
    }
    public function getDetailArticle(Request $request){
           $id = $request['id'];
           $res = Article::getDetailById($id) ?? '';
           return self::returnAjax($res, 200, "文章详情");
    }
}
